package com.zzzm.hospital.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.zzzm.hospital.R;

import java.util.List;

public class DepartmentSystemRightAdapter extends RecyclerView.Adapter<DepartmentSystemRightAdapter.DepartmentSystemRightHolder> {

    private Context context;
    private List<String> outPatientList;
    private OnListenerRightItem listener;

    public DepartmentSystemRightAdapter(Context context) {
        this.context = context;
    }

    public void setOutPatientList(List<String> outPatientList) {
        this.outPatientList = outPatientList;
    }

    public void setListener(OnListenerRightItem listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    public DepartmentSystemRightHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        DepartmentSystemRightHolder holder = new DepartmentSystemRightHolder(LayoutInflater.from(context).
                inflate(R.layout.department_system_right, null));
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull DepartmentSystemRightAdapter.DepartmentSystemRightHolder holder, int position) {
        TextView departmentRightText = holder.departmentSystemRightText;
        ImageView departmentRightImage = holder.departmentSystemRightImage;

        departmentRightText.setText(outPatientList.get(position));

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != listener) {
                    int positionItemNew=holder.getAdapterPosition();
                    listener.onClickRightItem(positionItemNew);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return null == outPatientList ? 0 : outPatientList.size();
    }

    class DepartmentSystemRightHolder extends RecyclerView.ViewHolder {

        TextView departmentSystemRightText;
        ImageView departmentSystemRightImage;

        public DepartmentSystemRightHolder(@NonNull View itemView) {
            super(itemView);
            departmentSystemRightText = itemView.findViewById(R.id.department_system_right_text);
            departmentSystemRightImage = itemView.findViewById(R.id.department_system_right_image);
        }
    }

    public interface OnListenerRightItem {
        void onClickRightItem(int position);
    }
}
